package java6681.lesson04;

import java.util.Arrays;
import java.util.Random;

/*
抢红包：
设计思路：
生成一个随机数后，将总和减去生成的随机数，再生成下一个


 */
public class RedPacket6681 {
    public static void main(String[] args) {
        int n = 8;
        int sum = 100;
        int[] arr = new int[n];
        randMoney(arr,sum);
        System.out.println(sumArr(arr) +","+ n);
        System.out.println(Arrays.toString(arr));
        System.out.println(sum);

        }
    static void randMoney(int[] arr,int sum){
        Random ran = new Random();
        while(sumArr(arr) != 100){
            for (int i = 0; i<arr.length;i++){
                int randNum = ran.nextInt(sum);
                arr[i] = randNum;
            }
        }

    }
    static int sumArr(int[] arr){
        int sum = 0;
        for (int i = 0;i<arr.length;i++){
            sum += arr[i];
        }
        return sum;
    }

    }

